package com.OA.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.OA.dao.Log_CY_mapper;
import com.OA.entity.DepartMentName;
import com.OA.entity.Log;
import com.OA.entity.LogComment;
import com.OA.entity.LogType;
import com.OA.entity.User;
import com.OA.entity.UserDept_Vo;
import com.OA.service.Log_CY_service;
import com.OA.util.Page;

@Service
public class Log_CY_serviceImpl implements Log_CY_service{

	@Autowired
	private Log_CY_mapper logMapper;
	
	/**
	 * 加载指定用户的日志
	 */
	public Page<Log> loadAllMyLogById(Map map) {
		List<Log> list = logMapper.loadAllMyLogById(map);
		int pageNo = (int) map.get("pageNo");
		int pageSize = (int) map.get("pageSize");
		int total = logMapper.logCountOfMy(map);
		Page<Log> page = new Page<>(pageNo,pageSize, total, list);
		return page;
	}
	
	/**
	 * 加载日志的所有类型
	 * @return
	 */
	public List<LogType> loadLogType(){
		List<LogType> list = logMapper.loadLogType();
		return list;
	}
	
	/**
	 * 加载部门名称
	 * @return
	 */
	public List<DepartMentName> loadDepartmentName(){
		List<DepartMentName> list = logMapper.loadDepartmentName();
		return list;
	}
	
	/**
	 * 加载用户本人的日志数量
	 * @param userId
	 * @return
	 */
	public int logCountOfMy(Map map){
		int count = logMapper.logCountOfMy(map);
		return count;
	}
	
	/**
	 * 加载该用户所有能看的其他用户的日志
	 * @param userId
	 * @return
	 */
	public Page<Log> loadOtherCanSee(Map map){
		List<Log> list = logMapper.loadOtherCanSee(map);
		int pageNo = (int) map.get("pageNo");
		int pageSize = (int) map.get("pageSize");
		int total = logCountCanSee(map);
		Page<Log> page = new Page<>(pageNo, pageSize, total, list);
		return page;
	}
	
	/**
	 * 加载用户可以查看其他用户的日志数量
	 * @param userId
	 * @return
	 */
	public int logCountCanSee(Map map){
		return logMapper.logCountCanSee(map);
	}
	
	/**
	 * 根据日志Id加载日志的内容
	 * @param logId
	 * @return
	 */
	public Log loadLogById(int logId){
		return logMapper.loadLogById(logId);
	}
	
	/**
	 * 加载日志的评论
	 * @param map
	 * @return
	 */
	public Page<LogComment> loadComments(Map map){
		List<LogComment> list = logMapper.loadComments(map);
		int pageNo = (int) map.get("pageNo");
		int pageSize = (int)map.get("pageSize");
		int logId = (int)map.get("logId");
		long total = logMapper.commentCount(logId);
		Page page = new Page<>(pageNo, pageSize, total, list);
		return page;
	}
	
	/**
	 * 提交评论
	 * @param map
	 */
	public void commitComment(Map map){
		logMapper.commitComment(map);
	}
	
	/**
	 * 展示这个日志可以查看的用户
	 * @param logId
	 * @return
	 */
	public List<Log> log_permissionUser(int logId){
		List<Log> list = logMapper.log_permissionUser(logId);
		return list;
	}

	/**
	 * 展示没有权限查看这个日志的用户
	 * @param logId
	 * @return
	 */
	public List<UserDept_Vo> log_permissionOutUser(int logId){
		List<Integer> list = logMapper.log_permissionOutUser(logId);
		List<UserDept_Vo> uv = new ArrayList<>();
		for(int userId : list){
			UserDept_Vo user = logMapper.userDept(userId);
			uv.add(user);
		}
		return uv;
	}
	






}
